/**
 * Created by Administrator on 2017/5/5.
 */



var homeBodyModule = require('../../ngModule/ngModuleHome');//请求

homeBodyModule.controller('homeBodyCtrl', ['$rootScope', '$scope', function ($rootScope, $scope) {

    $rootScope.navHighLight=['btn-primary-focus','','','','','','',''];//导航栏高亮显示

    console.log(344443);

    $.fn.extend({
        silder: function () {
            var childLi = $(this).find("li");
            //console.log( $("#slide>#slideBar>a"))
            var oDiv = $(this).find("#slideBar");
            var slideBarA = $(this).find("#slideBar").find("a");
            var slideTitleA = $(this).find("#slideTitle").find("a");
            var iNow = 0;
            var timer = null;

            auto();

            slideBarA.each(function () {
                $(this).mouseover(function () {
                    clearInterval(timer);
                    if ($(this).attr("class") != "current") {
                        childLi.each(function (i) {
                            $(this).fadeOut("slow");
                        });
                        slideBarA.each(function (i) {
                            $(this).removeClass("current");
                        });
                        slideTitleA.each(function (i) {
                            $(this).removeClass("current");
                        });
                        iNow = $(this).index();
                        childLi.eq(iNow).fadeIn("slow");
                        slideBarA.eq(iNow).addClass("current");
                        slideTitleA.eq(iNow).addClass("current");
                        $(this).mouseout(function () {
                            //iNow++;
                            auto();

                        });
                    }
                });
            });
            $(this).hover(function () {

                clearInterval(timer)

            }, function () {

                auto();

            });
            function auto() {


                clearInterval(timer);
                timer = setInterval(function () {

                    iNow++;
                    // iNow==childLi.size()&&(iNow=0);
                    childLi.each(function (i) {
                        $(this).fadeOut("slow");
                    });
                    slideBarA.each(function (i) {
                        $(this).removeClass("current");
                    });
                    slideTitleA.each(function (i) {
                        $(this).removeClass("current");
                    });
                    childLi.eq(iNow).fadeIn("slow");
                    slideBarA.eq(iNow).addClass("current");
                    slideTitleA.eq(iNow).addClass("current");


                }, 6000);


            }


        },


        createNav: function () {


            //console.log("1111");
            //console.log($("#global_menu>ul>li"));
            $("#global_menu>ul>li").each(function (index, el) {
                $(el).bind("mouseenter", function () {
                    $(this).find(".smenu").show();
                })
                $(el).bind("mouseleave", function () {
                    $(this).find(".smenu").hide();
                })

            });
        },

        searchKeywordFn: function () {

            $(this).focus(function () {
                var temp = $(this).val();
                $(this).val("");
                $(this).blur(function () {

                    if ($(this).val() == "") {
                        $(this).val(temp);
                    }
                });
            });

        },
        tabFn: function () {
            var tag = $(this).find(".tag span");
            var tagContent = $(this).find(".tagContent");
            var more = $(this).find("a.more");
            tag.each(function () {

                $(this).mouseover(function () {

                    var ALink = $(this).attr("rel");
                    tag.removeClass("current");
                    $(this).addClass("current");
                    tagContent.hide();
                    more.attr("href", ALink);

                    tagContent.eq($(this).index()).show();

                });
            });
        }
    });
    $(function () {
        $("#slide").silder();
        $("#global_menu").createNav();
        $(".section_l_sub2").tabFn();
    });
    console.log(11111111111);

    //图片轮播
    // window.onload=function () {
    console.log(7777777777);
    var oDiv = document.getElementById('div1');
    var oUl = oDiv.getElementsByTagName('ul')[0];
    var aLi = oUl.getElementsByTagName('li');
    var speed = 2;
    oUl.innerHTML = oUl.innerHTML + oUl.innerHTML;
    oUl.style.width = aLi[0].offsetWidth * aLi.length + 'px';
    function move() {
        console.log(8888888);
        if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
            oUl.style.left = '0';
        }
        if (oUl.offsetLeft > 0) {
            oUl.style.left = -oUl.offsetWidth / 2 + 'px';
        }
        oUl.style.left = oUl.offsetLeft + speed + 'px';
    }

    var timer = setInterval(move, 30);
    oDiv.onmouseover = function () {
        clearInterval(timer);
    }
    oDiv.onmouseout = function () {
        timer = setInterval(move, 30);
    }
    // }
    console.log(9999999999);
}]);